home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 2: CDPD 1 / Almathera Ten on Ten - Disc 2: CDPD 1.iso / pd / 301-325 / 325 / rexxhostlib / libmain.c < prev    next >
C/C++ Source or Header  |  1995-03-14  |  5KB  |  208 lines

  1. /* $Revision Header * Header built automatically - do not edit! *************
  2.  *
  3.  *    (C) Copyright 1990 by ???
  4.  *
  5.  *    Name .....: LibMain.c
  6.  *    Created ..: Sunday 07-Jan-90 18:55
  7.  *    Revision .: 6
  8.  *
  9.  *    Date            Author          Comment
  10.  *    =========       ========        ====================
  11.  *    07-Jan-90       Olsen           - Empty log message -
  12.  *    07-Jan-90       Olsen           Moved OpenLibrary call
  13.  *    07-Jan-90       Olsen           - Empty log message -
  14.  *    07-Jan-90       Olsen           Created this file!
  15.  *
  16.  ****************************************************************************
  17.  *
  18.  *    This Amiga shared library is based on example source code
  19.  *    written by Gary Samad & Bill Hawes. It also employs basic
  20.  *    library concepts introduced by Jimm Mackraz (ELib) and
  21.  *    Edwin Hoogerbeets (MkLib). This library was generated using
  22.  *    a customized version of the MkLib utility.
  23.  *
  24.  ****************************************************************************
  25.  *
  26.  *    An exec library compiled with Aztec 3.6a, small model.
  27.  *
  28.  *    Based on "elib", an example library:
  29.  *    created by jim mackraz using mylib.asm by neil katin.
  30.  *    May be used and distributed providing this comment block
  31.  *    is retained in the source code.
  32.  *
  33.  * $Revision Header ********************************************************/
  34.  #define REVISION 6
  35.  
  36. #include <exec/libraries.h>
  37. #include <devices/keymap.h>
  38. #include <exec/resident.h>
  39. #include <exec/memory.h>
  40. #include <exec/io.h>
  41.  
  42. #include "RexxHostBase.h"
  43.  
  44. typedef LONG (*PFL)();    /* pointer to function returning 32-bit int */
  45.  
  46.     /* Extern version reference. */
  47.  
  48. extern LONG Version;
  49.  
  50.     /* Library identifiers. */
  51.  
  52. char *LibName    = "rexxhost.library";
  53. char *LibId    = "rexxhost.library 1.6 (07 Jan 1990)\r\n";
  54.  
  55.     /* Some more extern references. */
  56.  
  57. extern struct Resident    LibRomTag;
  58. extern PFL        LibFuncTab[];
  59. extern LONG        LibInit();
  60. extern APTR        OpenLibrary();
  61.  
  62.     /* Main rexx library base. */
  63.  
  64. struct RxsLib *RexxSysBase = NULL;
  65.  
  66.     /* Library initialization table, used for AUTOINIT libraries. */
  67.  
  68. struct InitTable
  69. {
  70.     ULONG     it_DataSize;    /* Library data space size. */
  71.     PFL    *it_FuncTable;    /* Table of entry points. */
  72.     APTR     it_DataInit;    /* Table of data initializers. */
  73.     PFL     it_InitFunc;    /* Initialization function to run. */
  74. };
  75.  
  76.     /* Will do auto-init in LibInit. */
  77.  
  78. struct InitTable LibInitTab =
  79. {
  80.     sizeof(struct RexxHostBase),
  81.     LibFuncTab,
  82.     NULL,
  83.     LibInit
  84. };
  85.  
  86.     /* LibMain(LibBase,SegList) :
  87.      *
  88.      *    This function is Jimm's C-language library init-routine.
  89.      *    It is called by LibInit() after register saves and
  90.      *    small model initialization is done.
  91.      */
  92.  
  93. LONG
  94. LibMain(LibBase,SegList)
  95. struct RexxHostBase *LibBase;
  96. ULONG SegList;
  97. {
  98.     register struct RexxHostBase *TmpLibBase = LibBase;
  99.  
  100.         /* Magic cookie. */
  101.  
  102.     TmpLibBase -> rhb_SegList = SegList;
  103.  
  104.         /* Init. library structure (since I don't do
  105.          * automatic data init).
  106.          */
  107.  
  108.     TmpLibBase -> rhb_Lib . lib_Node . ln_Type    = NT_LIBRARY;
  109.     TmpLibBase -> rhb_Lib . lib_Node . ln_Name    = (char *)LibName;
  110.     TmpLibBase -> rhb_Lib . lib_Flags        = LIBF_SUMUSED | LIBF_CHANGED;
  111.     TmpLibBase -> rhb_Lib . lib_Version        = LibRomTag . rt_Version;
  112.     TmpLibBase -> rhb_Lib . lib_Revision        = Version;
  113.     TmpLibBase -> rhb_Lib . lib_IdString        = (APTR)LibId;
  114.  
  115.         /* Leave it zero. */
  116.     
  117.     TmpLibBase -> RexxSysBase            = NULL;
  118. }
  119.  
  120.     /* RealOpen(LibBase) :
  121.      *
  122.      *    Open library. Baseptr in A6, version in D0.
  123.      */
  124.  
  125. LONG
  126. RealOpen(LibBase)
  127. struct RexxHostBase *LibBase;
  128. {
  129.         /* Since we can't open the library in the main
  130.          * init routine (task switching turned off,
  131.          * as well as interrupt handling) we try to
  132.          * open it in the open routine.
  133.          */
  134.  
  135.     if(!RexxSysBase)
  136.         if(!(RexxSysBase = (struct RxsLib *)OpenLibrary(RXSNAME,0)))
  137.             return(NULL);
  138.  
  139.         /* Mark us as having another customer, this is a reentrant
  140.          * library.
  141.          */
  142.  
  143.     LibBase -> rhb_Lib . lib_OpenCnt++;
  144.     LibBase -> rhb_Lib . lib_Flags &= ~LIBF_DELEXP;
  145.  
  146.         /* Add the rexx library pointer. */
  147.  
  148.     LibBase -> RexxSysBase = RexxSysBase;
  149.  
  150.     return((LONG)LibBase);
  151. }
  152.  
  153.     /* RealExpunge(LibBase) :
  154.      *
  155.      *    Expunge library.
  156.      */
  157.  
  158. LONG
  159. RealExpunge(LibBase)
  160. struct RexxHostBase *LibBase;
  161. {
  162.     ULONG SegList = 0;
  163.     LONG LibSize;
  164.  
  165.     if(LibBase -> rhb_Lib . lib_OpenCnt == 0)
  166.     {
  167.             /* Really expunge: remove libbase and freemem. */
  168.  
  169.         SegList = LibBase -> rhb_SegList;
  170.  
  171.         Remove(LibBase);
  172.  
  173.         LibSize = LibBase -> rhb_Lib . lib_NegSize + LibBase -> rhb_Lib .lib_PosSize;
  174.         FreeMem((char *)LibBase - LibBase -> rhb_Lib . lib_NegSize,(LONG)LibSize);
  175.  
  176.         if(RexxSysBase)
  177.             CloseLibrary(RexxSysBase);
  178.     }
  179.     else
  180.         LibBase -> rhb_Lib . lib_Flags &= LIBF_DELEXP;
  181.  
  182.         /* Return NULL or real seglist. */
  183.  
  184.     return((LONG)SegList);
  185. }
  186.  
  187.     /* RealClose(LibBase) :
  188.      *
  189.      *    Close library.
  190.      */
  191.  
  192. LONG
  193. RealClose(LibBase)
  194. struct RexxHostBase *LibBase;
  195. {
  196.     LONG ReturnValue = 0;
  197.  
  198.         /* No more people have me open,
  199.          * and I have a delayed expunge pending:
  200.          * return segment list.
  201.          */
  202.  
  203.     if((--LibBase -> rhb_Lib . lib_OpenCnt == 0) && (LibBase -> rhb_Lib . lib_Flags & LIBF_DELEXP))
  204.         ReturnValue = RealExpunge();
  205.  
  206.     return(ReturnValue);
  207. }
  208.